package com.zhixing.web.common.utils;

import org.springframework.stereotype.Component;

/**
 * @author dzh
 * @version 1.0.0.05020
 * <p>project: d-blog</p>
 * <p>created time: 2022/05/02 15:17</p>
 * <p>describe: 主键生成工具类</p>
 * <p>remarks: </p>
 **/
@Component
public class KeyUtil {

    /**
     * 生成唯一的主键
     * 格式: 时间+随机数
     */
    public static synchronized Long genUniqueKey() {

        long keyid = System.currentTimeMillis() * 1000;

        return keyid + Long.parseLong(RandomNumUtil.genRandomNum(3));
    }
}